<?php

namespace Modules\My;

/**
 * Description of Index
 *
 * @author Admin
 */
class Vocabulary extends \Modules\My\Controller\General
{
	
	public function indexAction()
	{
		$this->_layout->meta()->title(_('Случайная карточка'));
		
		$this->rowset = \App::model('Vocabulary')->getRandomCart(1, $this->_userInfo['id']);
		
		$this->render();
		$this->render('left', 'right');
	}
	
	public function listAction()
	{
		$this->_layout->meta()->title(_('Мои карточки'));
		
		$this->rowset = \App::model('Vocabulary')->getList();
		
		$this->render();
		$this->render('left', 'right');
	}
	
	public function cardByIdAction()
	{
		$this->_layout->meta()->title(_('Карточка'));
		
		$this->row = \App::model('Vocabulary')->getById($this->getIdByUrl());
		
		if(!$this->row)
			return $this->_404();
		
		$this->_layout->meta()->title($this->row['title']);
		
		$this->render('card-by-id');
		$this->render('left', 'right');
	}
	
	public function addAction()
	{
		$this->_layout->meta()->title(_('Добавить карточку'));
		
		if($this->_isPost())
		{
			$itemId = \App::model('Vocabulary')->addCart($this->_userInfo['id'], $this->_getPost(), $this->_lang);
			
			if($itemId > 0)
				return $this->_redirect ($this->_layout->url('myCarts'));
		}
		
		$id = $this->getIdByUrl();
		
		$this->row = array();
		
		if($id)
		{
			$this->row = \App::model('Vocabulary')->getById($id);
		}
		
		
		$this->render();
		$this->render('left', 'right');
	}
	
}
